<template>
  <div class="admin-container">
    <div
      style="margin-bottom: 10px; display: flex; align-items: center"
      v-show="queryType"
    >
      <el-form
        :model="query"
        :rules="query"
        ref="query"
        :inline="true"
        class="demo-form-inline"
      >
        <el-form-item label="公司名称">
          <el-select v-model="query.companyId" placeholder="请选择公司" filterable >
            <el-option
              :label="item.name"
              :value="item.id"
              v-for="item in companyList"
              :key="item.id"
            ></el-option>
          </el-select>
          </el-form-item> 
        <el-form-item>
          <el-button type="primary" @click="submitQuery">查询</el-button>
          <el-button @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column prop="projectName" label="项目名称" align="center">
      </el-table-column>
      <el-table-column prop="projectCategoryId" label="项目类别" align="center">
      </el-table-column>
      <el-table-column prop="compnayName" label="公司名称" align="center">
      </el-table-column>
      <el-table-column prop="startDate" label="启动时间" align="center">
      </el-table-column>
      <el-table-column label="项目状态" align="center">
        <template slot-scope="scope">
          <div>{{projectStatusFormate("project_status-"+scope.row.status)}}</div>
        </template>
      </el-table-column>
      <el-table-column prop="memo" label="驳回说明"" align="center"> </el-table-column>
      
      <el-table-column fixed="right" label="操作">
        <template slot-scope="scope">
          <el-button @click="viewProject(scope.row)" type="text" size="small"
            >查看详情</el-button
          >
          <el-button type="text" size="small" v-permission="['project.audit']" v-if="scope.row.status==1" @click="auditproject(scope.row)"
              >审核项目</el-button
            >
            <!--<el-button type="text" size="small" @click="projectExecute(scope.row)"
              >运营月报</el-button
            >
            <el-button type="text" size="small" @click="projectActivity(scope.row)"
              >查看活动</el-button
            > -->
        </template>
      </el-table-column>
    </el-table>
    <el-footer class="el-footerBox">
      <el-pagination
        background
        layout="prev, pager, next"
        :total="total"
        :page-size="pageSize"
        :current-page.sync="pageNum"
        @current-change="getProjectList"
      >
      </el-pagination>
    </el-footer>
    <!-- </div> -->
  </div>
</template>

<script>
import permission from '@/directive/permission/index.js' // 权限判断指令
import { validUsername } from "@/utils/validate";
import utils from "@/utils/utils.js";
import { list as adminCompanyList } from "@/api/adminCompany";
import { list as adminProjectList } from "@/api/adminProject";

export default {
  directives: { permission },
  components: {},
  name: "project",
  data() {
    return {
      queryType: true,
      query: {
        companyId: "",
      },
      total: 0,
      pageNum: 1,
      pageSize: 20,
      tableData: [],
      companyList: [],

      //字典信息
    projectStatusDict:[],
    projectStatusDictPromise:"",
    };
  },
  watch: {
    $route: {
      handler: function (route) {},
      immediate: true,
    },
  },

  created() {
    this.projectStatusDictPromise = utils.getDictList("project_status", (res) => {
      this.projectStatusDict = res.data;
    });
  },

  mounted() {
    let _this = this
    this.gatAdminCompanyList();
    Promise.all([this.taxTypeDictPromise, this.registrationDictPromise]).then(
      (res) => {
        //console.log("字典已经全部加载完成--");
        this.getProjectList();
      }
    );
  },

  destroyed() {},

  methods: {
    //获取项目列表
    getProjectList() {
      let _this = this;
      let params = new URLSearchParams();
      params.append("companyId", _this.query.companyId);
      params.append("pageNum", _this.pageNum);
      params.append("pageSize", _this.pageSize);
      adminProjectList(params)
        .then((res) => {
          console.log("ProjectList成功获取数据--", res);
          if (res.type == "success") {
            this.tableData = res.data.data;
            this.total = res.data.total;
            if (this.tableData.length > 0) {
              this.tableData.map((item) => {
                item.startDate = utils.dateFormatter(item.startDate);
              });
            }
          }
        })
        .catch((err) => {
          this.$message.error(err.msg);
        });
    },

    //条件查询
    submitQuery() {
      console.log("query--", this.query);
      this.getProjectList();
    },

    //条件查询
    resetQuery() {
      this.query = {
        companyId: "",
      };
      this.getProjectList();
    },

    //查看项目
    viewProject(data) {
      this.$router.push({
        path: "/admin/project/view",
        query: { projectId: data.id },
      });
    },

    //审核项目
    auditproject(data) {
      this.$router.push({
        path: "/admin/project/audit",
        query: { projectId: data.id },
      });
    },

    //编辑项目
    editProject(data) {
      this.$router.push({
        path: "/project/edit",
        query: { projectId: data.id, companyId: this.companyId },
      });
    },

    //项目月报表
    projectExecute(data) {
      this.$router.push({
        path: "/projectExecute/list",
        query: { projectId: data.id, companyId: this.companyId },
      });
    },

    //项目活动表
    projectActivity(data) {
      this.$router.push({
        path: "/projectActivity/list",
        query: { projectId: data.id, companyId: this.companyId },
      });
    },

    //获取公司信息
    gatAdminCompanyList() {
      adminCompanyList().then((res) => {
        console.log("获取公司信息res--", res);
        if (res.type == "success") {
          this.companyList = res.data.data;
        }
      });
    },

    projectStatusFormate(data) {
      return utils.selectDictLabel(this.projectStatusDict, data);
    },
  },
};
</script>

<style lang="scss" scoped>
.el-pagination {
  display: block;
}
.el-col {
  border: solid 1px black;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 30px;
  border-collapse: collapse !important;
}

.leftAlign-pd30 {
  justify-content: left;
  padding-left: 30px;
}
.leftAlign-pd40 {
  justify-content: left;
  padding-left: 40px;
}
.leftAlign-pd80 {
  justify-content: left;
  padding-left: 80px;
}
</style>
